package com.doitedu.hbase.client;

import com.doitedu.hbase.utils.HbaseUtil;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Date 2021/12/13
 * @Created by HANGGE
 * @Description
 * Get 对象确定的是表中的一行数据
 *     直接调用get(get)  获取的是一行数据
 *     通过get.addColumn 和 get.addFamily  获取指定的列 或者是指定的列族数据
 */
public class C05_Get {
    public static void main(String[] args) throws Exception {
        Connection conn = HbaseUtil.getConnection();
        Table tb_teacher = HbaseUtil.getTable("tb_teacher", conn);
        getMoreRowData(tb_teacher);

        tb_teacher.close();
        conn.close();

    }

    private static void getMoreRowData(Table tb_teacher) throws IOException {
        //创建多个Get对象
        Get get1 = new Get("rk001".getBytes());
        get1.addColumn("info".getBytes(),"name".getBytes()) ;
        Get get2 = new Get("rk002".getBytes());
       /* List<Get> list= new ArrayList<>();
        list.add(get1);
        list.add(get2);*/
        List<Get> list = Arrays.asList(get1, get2);
        Result[] results = tb_teacher.get(list);
        for (Result result : results) {
            HbaseUtil.show(result);
        }
    }

    private static void getOneRowData(Table tb_teacher) throws IOException {
        //Get(byte[] row)
        Get get = new Get("rk001".getBytes());  // 没有额外的参数设置  获取的是行的所有数据
     /*   get.addColumn()
          get.addFamily()*/
        // Get数据
        Result result = tb_teacher.get(get);

        HbaseUtil.show(result);
    }
}
